#!/bin/sh
# update-usbids for puppy linux

#-----------------------------------------
URL="http://www.linux-usb.org/usb.ids.bz2"
#-----------------------------------------

[ "$ROOTDIR" ] || ROOTDIR="${ROOTDIR}"
[ -d "$1" ] && ROOTDIR="$1"
ROOTDIR=${ROOTDIR%/}

exit_error() {
	echo "$@"
	exit 1
}

mkdir -p ${ROOTDIR}/usr/share/hwdata
mkdir -p ${ROOTDIR}/usr/share/misc
mkdir -p ${ROOTDIR}/var/lib/usbutils

wget --no-check-certificate -O ${ROOTDIR}/usr/share/hwdata/usb.ids.bz2 $URL || exit_error "error downloading usb.ids.bz2"

rm -f ${ROOTDIR}/usr/share/hwdata/usb.ids 2>/dev/null
rm -f ${ROOTDIR}/usr/share/misc/usb.ids 2>/dev/null
rm -f ${ROOTDIR}/usr/share/usb.ids 2>/dev/null
rm -f ${ROOTDIR}/var/lib/usbutils/usb.ids 2>/dev/null

bunzip2 ${ROOTDIR}/usr/share/hwdata/usb.ids.bz2 || exit_error "error uncompressing usb.ids.bz2"
ln -sf ../../../usr/share/hwdata/usb.ids ${ROOTDIR}/usr/share/misc/usb.ids
ln -sf ../../usr/share/hwdata/usb.ids ${ROOTDIR}/usr/share/usb.ids
ln -sf ../../../usr/share/hwdata/usb.ids ${ROOTDIR}/var/lib/usbutils/usb.ids

echo usb.ids $(grep -o 'Version: .*' ${ROOTDIR}/usr/share/misc/usb.ids)

### END ###
